<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/3/29
 * Time: 15:04
 */

namespace common\components\helpers;



class Pay
{

   public static function getpayment(){

       $path = \Yii::getAlias('@doumiaoduo/payment');
       return self::getfiles($path,'php');
   }


    /**
     * 遍历获取目录下的指定类型的文件
     * @param $path
     * @param array $files
     * @return array
     */
    public static function getfiles($path,$allowFiles, &$files = array())
    {
        if (!is_dir($path)) return null;
        if(substr($path, strlen($path) - 1) != '/') $path .= '/';
        $handle = @opendir($path);
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..') {
                $path2 = $path . $file;
                if (preg_match("/^.*?\.".$allowFiles."$/", $file)) {
                    $file = pathinfo($file);
                    $file = 'doumiaoduo\payment\\'.$file['filename'];
                    $pay = new $file();
                    $f['name'] = $pay->name;
                    $f['key'] = $pay->app_key;
                    $f['version'] = $pay->version;
                    $f['author'] = $pay->author;
                    $f['intro'] = $pay->intro();
                    $files[] = $f;
                }
            }
        }
        return $files;
    }


}